﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using QunYing.Model;
namespace QunYing.BLL
{
    /// <summary>
    /// UserLoginInfo
    /// </summary>
    public partial class UserLoginInfo
    {
        private readonly QunYing.DAL.UserLoginInfo dal = new QunYing.DAL.UserLoginInfo();
        public UserLoginInfo()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string 用户ID)
        {
            return dal.Exists(用户ID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(QunYing.Model.UserLoginInfo model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(QunYing.Model.UserLoginInfo model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string 用户ID)
        {

            return dal.Delete(用户ID);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string 用户IDlist)
        {
            return dal.DeleteList(用户IDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public QunYing.Model.UserLoginInfo GetModel(string 用户ID)
        {

            return dal.GetModel(用户ID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public QunYing.Model.UserLoginInfo GetModelByCache(string 用户ID)
        {

            string CacheKey = "UserLoginInfoModel-" + 用户ID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(用户ID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (QunYing.Model.UserLoginInfo)objModel;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<QunYing.Model.UserLoginInfo> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<QunYing.Model.UserLoginInfo> DataTableToList(DataTable dt)
        {
            List<QunYing.Model.UserLoginInfo> modelList = new List<QunYing.Model.UserLoginInfo>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                QunYing.Model.UserLoginInfo model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new QunYing.Model.UserLoginInfo();
                    if (dt.Rows[n]["用户ID"] != null && dt.Rows[n]["用户ID"].ToString() != "")
                    {
                        model.用户ID = dt.Rows[n]["用户ID"].ToString();
                    }
                    if (dt.Rows[n]["手机号码"] != null && dt.Rows[n]["手机号码"].ToString() != "")
                    {
                        model.手机号码 = dt.Rows[n]["手机号码"].ToString();
                    }
                    if (dt.Rows[n]["电邮地址"] != null && dt.Rows[n]["电邮地址"].ToString() != "")
                    {
                        model.电邮地址 = dt.Rows[n]["电邮地址"].ToString();
                    }
                    if (dt.Rows[n]["密码"] != null && dt.Rows[n]["密码"].ToString() != "")
                    {
                        model.密码 = dt.Rows[n]["密码"].ToString();
                    }
                    if (dt.Rows[n]["角色"] != null && dt.Rows[n]["角色"].ToString() != "")
                    {
                        model.角色 = dt.Rows[n]["角色"].ToString();
                    }
                    if (dt.Rows[n]["最后登录时间"] != null && dt.Rows[n]["最后登录时间"].ToString() != "")
                    {
                        model.最后登录时间 = DateTime.Parse(dt.Rows[n]["最后登录时间"].ToString());
                    }
                    if (dt.Rows[n]["验证信息"] != null && dt.Rows[n]["验证信息"].ToString() != "")
                    {
                        model.验证信息 = dt.Rows[n]["验证信息"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

